package com.naiterui.ehp.bs.doctor.controller.openapi;

import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bs.doctor.service.ITencentDetectService;
import com.naiterui.ehp.bs.patient.exception.ExceptionCodes;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 腾讯云人脸识别回调API
 **/
@Slf4j
@RequestMapping("ad/openapi/tencent")
@RestController
@RequiredArgsConstructor
public class TencentCallbackController {

    private final ITencentDetectService tencentDetectService;

    /**
     * 腾讯云人脸识别回调
     */
    @SneakyThrows
    @GetMapping("detect/callback")
    public ResponseVO<Void> callback(String code, String orderNo, String h5faceId, String newSignature, String liveRate, HttpServletResponse response) {
        log.info("腾讯云人脸识别回调 code:{}, orderNo:{}, h5faceId:{}, signature {}, liveRate:{}", code, orderNo, h5faceId, newSignature, liveRate);
        String redirect = tencentDetectService.callbackH5Redirect(code, orderNo, h5faceId, newSignature, liveRate);
        response.sendRedirect(redirect);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS);
    }
}
